package com.study.controller;

import com.study.entity.Order;
import com.study.service.HbaseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/order")
public class HbaseOrderController {
    @Autowired
    private HbaseOrderService hbaseOrderService;

    @RequestMapping("/add")
    public String add(@RequestBody Order user){
        hbaseOrderService.insert(user);
        return "ok";
    }

    @RequestMapping("/single/{rowkey}")
    public Order select(@PathVariable("rowkey") String rowkey){
        return hbaseOrderService.findByRowkey(rowkey);
    }

    @RequestMapping("/delete/{rowkey}")
    public String delete(@PathVariable("rowkey") String rowkey){
        return hbaseOrderService.delete(rowkey);
    }

    @RequestMapping("/getAll")
    public List<Order> getAll(){
        return hbaseOrderService.findAll();
    }

    @RequestMapping("/findByOrderNo/{orderNo}")
    public List<Order> findByOrderNo(@PathVariable("orderNo") String orderNo){
        return hbaseOrderService.findUserByPrefixName(orderNo);
    }
}
